//5
//5000 2000 5000 8000 1800
// 输入数据是上面这样的, 需要计算构造的三茶树的高度
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

class TreeNode {
    constructor(value, height = 1, left = null, center = null, right = null,) {
        this.value = value
        this.height = height
        this.left = left
        this.center = center
        this.right = right
    }
}


let n;
let initArr = [];
rl.on("line", (line) => {
    if (n === undefined) {
        n = Number(line.trim())
    } else if (initArr.length === 0) {
        initArr = line.trim().split(/\s+/).map(Number)
        console.log(getResult(n, initArr))

        // clear
        n = undefined
        initArr.length = 0
    }
})

function getResult(n, initArr) {
    let root = new TreeNode(initArr[0])
    let ans = 0
    // 就是一个dfs, 把高度收集起来
    let index = 1
    while (index < n) {
        let parent = root
        let num = initArr[index]
        let current = new TreeNode(num)
        while (true) {
            let parentNum = parent.value
            if (parentNum - 500 > num) {
                //left
                if (parent.left) {
                    parent = parent.left
                } else {
                    current.height = parent.height + 1
                    ans = Math.max(ans, current.height)
                    parent.left = current
                    index++
                    break
                }
            } else if (parentNum + 500 < num) {
                //right
                if (parent.right) {
                    parent = parent.right
                } else {
                    current.height = parent.height + 1
                    ans = Math.max(ans, current.height)
                    parent.right = current
                    index++
                    break

                }
            } else {
                // center
                if (parent.center) {
                    parent = parent.center
                } else {
                    current.height = parent.height + 1
                    ans = Math.max(ans, current.height)
                    parent.center = current
                    index++
                    break
                }
            }
        }
    }
    return ans
}